﻿using AutoMapper;
using B.S.Procurement.Domain;
using B.S.Procurement.Error;
using B.S.Procurement.Read.Api.Application.Command.ClientCommand;
using MediatR;
using SqlSugar;

namespace B.S.Procurement.Read.Api.Application.CommandHander.ClientCommandHander
{
    public class GetClientCommandHander : IRequestHandler<GetClientCommand, ApiResult<List<Client>>>
    {
        private readonly IMapper mapper;
        private readonly ISqlSugarClient db;

        public GetClientCommandHander(IMapper mapper, ISqlSugarClient db)
        {
            this.mapper = mapper;
            this.db = db;
        }

        public async Task<ApiResult<List<Client>>> Handle(GetClientCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<Client>> result = new ApiResult<List<Client>>();

            var item = await db.Queryable<Client>().Where(x => x.Del == false).ToListAsync();

            result.Code = ApiEnum.success;
            result.Msg = "查询产品信息成功";
            result.Data = item;

            return result;
        }
    }
}
